﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage_New.master" AutoEventWireup="true" CodeBehind="WarningSetupForSubsidy2.aspx.cs" Inherits="HZ.Supervise.Web.Message.WarningSetupForSubsidy2" %>
<%@ Register Src="~/Common/QueryControl.ascx" TagName="QueryControl" TagPrefix="uc1" %>
<%@ Register Src="../Common/ChartControl.ascx" TagName="ChartControl" TagPrefix="uc2" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type="text/javascript">
        $().ready(function() {
            $("form").validate();
        });
    
    </script>

    <script type="text/javascript" language="javascript">
        //选择医院  
        function SelectHospital() {
            var AreaName = document.getElementById("ctl00_ContentPlaceHolder1_txtArea");
            var AreaId = document.getElementById("ctl00_ContentPlaceHolder1_hfdRecivedArea");
            if (AreaName.value == null || AreaName.value == "") {
                alert("请先选择地区");
            }
            else {
                showPopWin('选择医院', '../Common/SelectHospital.aspx?flag=1&AreaId=' + AreaId.value + '&AreaName=' + AreaName.value, 800, 400, null, true, true)
                //window.open('../Common/SelectHospital.aspx?flag=1&AreaId=' + AreaId.value + '&AreaName=' + AreaName.value + '', 'selectReciever', 'width=800,height=400,resizable=0,scrollbars=1, status=0, toolbar=0, menubar=0');
            }
        }
        function SelectGoods() {
            var Sort = document.getElementById("ctl00_ContentPlaceHolder1_ddlDrugSort");
            var SortSource = document.getElementById("ctl00_ContentPlaceHolder1_ddlSortSource");
            showPopWin('选择药品', '../Common/SelectGoods.aspx?SortId=' + 0 + '&SortSource=' + encodeURI(SortSource.value), 800, 400, null, true, true)
            //window.open('../Common/SelectGoods.aspx?SortId=' + 0 + '&SortSource=' + encodeURI(SortSource.value) + '', 'selectReciever', 'width=800,height=400,resizable=0,scrollbars=1, status=0, toolbar=0, menubar=0');
        }

        //将选择的药品放入文本框
        function insertGoodsInfo(GoodsId, ProductName) {
            var varGoodsId = GoodsId;
            var varProductName = ProductName;
            var GoodsID = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedGoods");
            var GoodsName = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedGoodsName");
            var ProductName = document.getElementById("ctl00_ContentPlaceHolder1_txtGoods");
            ProductName.value = varProductName;
            GoodsName.value = varProductName;
            GoodsID.value = varGoodsId;
            //
            if ($("#ctl00_ContentPlaceHolder1_txtGoods").attr("value") != "") {
                $("#ctl00_ContentPlaceHolder1_ddlDrugSort").attr("disabled", "disabled");
                $("#ctl00_ContentPlaceHolder1_ddlSortSource").attr("disabled", "disabled");
            }
        }

        //将选择的医院放入文本框
        function insertHospitalInfo(HospitalId, HospitalName) {
            var varHospitalId = HospitalId;
            var varHospitalName = HospitalName;
            var hospitalID = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedHospital");
            var hospitalNameShow = document.getElementById("ctl00_ContentPlaceHolder1_txtHospital");
            var hospitalName = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedHospitalName");
            hospitalName.value = varHospitalName;
            hospitalNameShow.value = varHospitalName;
            hospitalID.value = varHospitalId;
            //
            if ($("#ctl00_ContentPlaceHolder1_txtHospital").attr("value") != "") {
                $("#SelectArea").attr("disabled", "disabled");
            }
        }

        //将选择的企业放入文本框
        function insertCompanyInfo(CompanyId, CompanyName) {
            var varCompanyId = CompanyId;
            var varCompanyName = CompanyName;
            var hospitalID = document.getElementById("ctl00_ContentPlaceHolder1_hdfCompanyId");
            var hospitalNameShow = document.getElementById("ctl00_ContentPlaceHolder1_txtCompany");

            hospitalNameShow.value = varCompanyName;
            hospitalID.value = CompanyId;
            //
            if ($("#ctl00_ContentPlaceHolder1_txtHospital").attr("value") != "") {
                $("#SelectArea").attr("disabled", "disabled");
            }
        }

        //将选择的地区放入文本框
        function insertAreaInfo(AreaId, AreaName) {
            var varAreaId = AreaId;
            var varAreaName = AreaName;
            var RecievedareaID = document.getElementById("ctl00_ContentPlaceHolder1_hfdRecivedArea");
            var RecievedareaNameShow = document.getElementById("ctl00_ContentPlaceHolder1_txtArea");
            var RecievedareaName = document.getElementById("ctl00_ContentPlaceHolder1_hfdRecivedAreaName");
            RecievedareaNameShow.value = varAreaName;
            RecievedareaName.value = varAreaName;
            RecievedareaID.value = varAreaId;
            //显示医院，类别
            if ($("#ctl00_ContentPlaceHolder1_txtArea").attr("value") != "") {
                $(".hospitalshoworhide").show();
                $("#ctl00_ContentPlaceHolder1_txtHospital").attr("value", "所有医院");
            }
            else {
                $(".hospitalshoworhide").hide();
            }
        }  
    </script>

    <script type="text/javascript">


        $(document).ready(function() {
            $("#ctl00_ContentPlaceHolder1_txtArea").attr("value", "所有地区");
            $("#ctl00_ContentPlaceHolder1_txtHospital").attr("value", "所有医院");
            $("#ctl00_ContentPlaceHolder1_txtGoods").attr("value", "所有药品");


            $("#ctl00_ContentPlaceHolder1_ddlSortSource").change(function() {
                var ddl = $("#ctl00_ContentPlaceHolder1_ddlSortSource").attr("value");
                if (ddl == "") {
                    $("#ctl00_ContentPlaceHolder1_txtGoods").attr("value", "所有药品");
                }
                else if ($("#ctl00_ContentPlaceHolder1_ddlSortSource").attr("value") == "0") {
                    $("#ctl00_ContentPlaceHolder1_txtGoods").attr("value", "所有基药");
                }
                else if ($("#ctl00_ContentPlaceHolder1_ddlSortSource").attr("value") == "1") {
                    $("#ctl00_ContentPlaceHolder1_txtGoods").attr("value", "所有非基药");
                }
            });

            $("#ctl00_ContentPlaceHolder1_txtCount").blur(function() {
                if ($("#ctl00_ContentPlaceHolder1_txtCount2").attr("value") != "") {
                    if ($("#ctl00_ContentPlaceHolder1_txtCount2").attr("value") == $("#ctl00_ContentPlaceHolder1_txtCount").attr("value")) {
                        alert("预警数量不能一样！");
                        $("#ctl00_ContentPlaceHolder1_txtCount2").focus();
                    }
                }
            });
            $("#ctl00_ContentPlaceHolder1_txtCount2").blur(function() {
                if ($("#ctl00_ContentPlaceHolder1_txtCount").attr("value") != "") {
                    if ($("#ctl00_ContentPlaceHolder1_txtCount2").attr("value") == $("#ctl00_ContentPlaceHolder1_txtCount").attr("value")) {
                        alert("预警数量不能一样！");
                        $("#ctl00_ContentPlaceHolder1_txtCount").focus();
                    }
                }
            });

            $("#ctl00_ContentPlaceHolder1_txtAmount").blur(function() {
                if ($("#ctl00_ContentPlaceHolder1_txtAmount2").attr("value") != "") {
                    if ($("#ctl00_ContentPlaceHolder1_txtAmount").attr("value") == $("#ctl00_ContentPlaceHolder1_txtAmount2").attr("value")) {
                        alert("预警金额不能一样！");
                        $("#ctl00_ContentPlaceHolder1_txtAmount2").focus();
                    }
                }
            });
            $("#ctl00_ContentPlaceHolder1_txtAmount2").blur(function() {
                if ($("#ctl00_ContentPlaceHolder1_txtAmount").attr("value") != "") {
                    if ($("#ctl00_ContentPlaceHolder1_txtAmount2").attr("value") == $("#ctl00_ContentPlaceHolder1_txtAmount").attr("value")) {
                        alert("预警金额不能一样！");
                        $("#ctl00_ContentPlaceHolder1_txtAmount").focus();
                    }
                }
            });
            $("#ctl00_ContentPlaceHolder1_btnConfirmMessage").click(function() {
                if ($("#ctl00_ContentPlaceHolder1_txtCount").attr("value") == "" && $("#ctl00_ContentPlaceHolder1_txtCount2").attr("value") == "" && $("#ctl00_ContentPlaceHolder1_txtAmount2").attr("value") == "" && $("#ctl00_ContentPlaceHolder1_txtAmount").attr("value") == "") {
                    alert("预警数量与预警金额必填一样");
                    return false;
                }
            });

            $("#FirstClear").click(function() {
                $("#SelectArea").attr("disabled", "");
                $("#ctl00_ContentPlaceHolder1_txtArea").attr("value", "所有地区");
                $("#ctl00_ContentPlaceHolder1_hfdRecivedArea").attr("value", "");
                $("#ctl00_ContentPlaceHolder1_hfdRecivedAreaName").attr("value", "");
                $("#ctl00_ContentPlaceHolder1_txtHospital").attr("value", "所有医院");
                $("#ctl00_ContentPlaceHolder1_hdfRecivedHospital").attr("value", "");
                $("#ctl00_ContentPlaceHolder1_hdfRecivedHospitalName").attr("value", "");
            });
            $("#SecondClear").click(function() {
                $("#ctl00_ContentPlaceHolder1_ddlDrugSort").attr("disabled", "");
                $("#ctl00_ContentPlaceHolder1_ddlSortSource").attr("disabled", "");
                $("#ctl00_ContentPlaceHolder1_txtGoods").attr("value", "所有药品");
                $("#ctl00_ContentPlaceHolder1_hdfRecivedGoods").attr("value", "");
                $("#ctl00_ContentPlaceHolder1_hdfRecivedGoodsName").attr("value", "");
            });

            $("#CompanyClear").click(function() {
                $("#ctl00_ContentPlaceHolder1_hdfCompanyId").attr("disabled", "");
                $("#ctl00_ContentPlaceHolder1_txtCompany").attr("value", "请选择企业");
            });

        });
    </script>

    <div id="tabnav">
        <ul>
          
            <li class="active"><a href="WarningSetupForHospital.aspx">处方单预警</a> </li>
        </ul>
    </div>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td colspan="6">
                <span class="style4" style="text-align:left">
                <label style="color: Red">
                设置地区医院</label> </span>
            </td>
        </tr>
        <tr>
            <th align="right" class="style1" height="21">
                地区 
            </th>
            <td align="left" class="style6" colspan="2">
                <asp:TextBox ID="txtArea" runat="server" CssClass="required" Enabled="false" 
                    Width="250px"></asp:TextBox>
                <asp:HiddenField ID="hfdRecivedArea" runat="server" EnableViewState="true" />
                <asp:HiddenField ID="hfdRecivedAreaName" runat="server" 
                    EnableViewState="true" />
                <input id="SelectArea" class="btn" 
                    onclick="javascript:showPopWin('选择地区','../Common/SelectArea.aspx', 300,400, null,true,true);" 
                    type="button" value="选择地区" />
            </td>
            <td align="right" class="style17">
              <b>医院</b></td>
            <td align="left" class="style19">
                <span class="hospitalshoworhide">
                <asp:TextBox ID="txtHospital" runat="server" Enabled="false" Width="299px"></asp:TextBox>
                <asp:HiddenField ID="hdfRecivedHospital" runat="server" 
                    EnableViewState="true" />
                <asp:HiddenField ID="hdfRecivedHospitalName" runat="server" 
                    EnableViewState="true" />
                <input class="btn" name="button3" onclick="javascript:SelectHospital();" 
                    type="button" value="选择医院" /> </span>
            </td>
            <td align="right" class="style18">
                <input id="FirstClear" class="btn" name="button2" type="button" value="清空状态" />
            </td>
        </tr>
        <tr>
            <td colspan="6">
                <hr />
            </td>
        </tr>
        <%--<tr>
            <td colspan="6">
                <span class="style3" style="text-align:left">
                <label style="color: Red">
                设置企业</label> </span>
            </td>
        </tr>--%>
        <%--<tr>
            <th id="Th5" align="right" class="style1">
                企业名称 
            </th>
            <td id="Td5" align="left" class="style5" colspan="4">
                <asp:TextBox ID="txtCompany" runat="server" Enabled="false" Text="请选择企业" 
                    Width="250px"></asp:TextBox>
                <asp:HiddenField ID="hdfCompanyId" runat="server" EnableViewState="true" />
                <input class="btn" 
                    onclick="window.open('../Common/FindAllCompany.aspx','selectReciever','width=400,height=500,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0');" 
                    type="button" value="选择企业" />
            </td>
            <td align="right" class="style18">
                <input id="CompanyClear" class="btn" name="button" type="button" value="清空状态" />
            </td>
        </tr>--%>
        <tr>
            <td colspan="6">
                <span class="style16" style="text-align:left">
                <label style="color: Red">
                <nobr>
                设置触发条件</nobr>
                </label>
                </span>
            </td>
        </tr>
        <tr>
            <th id="warningCount" align="right" class="style1" height="44">
                预警品规数量 
            </th>
            <td id="txtWarningCount" align="left" class="style6" colspan="2">
                <asp:DropDownList ID="ddlCountCompare" runat="server">
                    <asp:ListItem Selected="True" Value="1">大于等于</asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox ID="txtCount" runat="server" CssClass="digits" MaxLength="12" 
                    Width="70px"></asp:TextBox>
                <asp:DropDownList ID="ddlCountCompare2" runat="server">
                    <asp:ListItem Selected="True" Value="0">小于等于</asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox ID="txtCount2" runat="server" CssClass="digits" MaxLength="12" 
                    Width="70px"></asp:TextBox>
            </td>
            <th id="warningAmount" align="right" class="style17">
                预警金额 
            </th>
            <td id="txtWarningAmount" align="left" class="style19" colspan="2">
                <asp:DropDownList ID="ddlAmountCompare" runat="server">
                    <asp:ListItem Selected="True" Value="1">大于等于</asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox ID="txtAmount" runat="server" CssClass="digits " MaxLength="15" 
                    Width="103px"></asp:TextBox>
                <asp:DropDownList ID="ddlAmountCompare2" runat="server">
                    <asp:ListItem Selected="True" Value="0">小于等于</asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox ID="txtAmount2" runat="server" CssClass="digits " MaxLength="15" 
                    Width="103px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <th id="ConnectType" align="right" class="style20">
                触发规则 
            </th>
            <td align="left" class="style21" colspan="2">
                <asp:DropDownList ID="ddlConnectType" runat="server" Height="20px" >
                    <asp:ListItem Selected="True" Text="预警金额和数量都满足" Value="1"></asp:ListItem>
                    <asp:ListItem Text="预警金额和数量任意一个满足" Value="0"></asp:ListItem>
                </asp:DropDownList>
                <br />
                <br />
            </td>
            <th id="level" align="right" class="style22">
                预警级别 
            </th>
            <td id="ddlLeve" align="left" class="style23">
                <asp:DropDownList ID="ddlLevel" runat="server" Height="20px" Width="98px">
                    <asp:ListItem Text="一级预警" Value="1"></asp:ListItem>
                    <asp:ListItem Text="二级预警" Value="2"></asp:ListItem>
                    <asp:ListItem Text="三级预警" Value="3"></asp:ListItem>
                </asp:DropDownList>
            </td>
            <td class="style24">
                </td>
        </tr>
        <tr>
            <th id="warningRange" align="right" class="style1">
                预警范围 
            </th>
            <td id="ddlWarningRange" align="left" class="style1" colspan="2">
                <asp:TextBox ID="txtTimeOfRange" runat="server" CssClass="digits required" 
                    MaxLength="10" Width="215px"></asp:TextBox>
                <asp:DropDownList ID="ddlTime" runat="server" Width="57px">
                    <asp:ListItem Text="日" Value="1"></asp:ListItem>
                    <asp:ListItem Text="周" Value="2"></asp:ListItem>
                    <asp:ListItem Text="月" Value="3"></asp:ListItem>
                </asp:DropDownList>
                <br />
            </td>
            <th id="level0" align="right" class="style1">
                </th>
            <td id="ddlLeve0" align="left" class="style1">
                </td>
            <td class="style1">
             
            </td>
        </tr>
        <tr>
            <td class="style1">
            </td>
            <td></td>
            <td></td>
         <td class="style18"  align="center" >
              
                <asp:Button ID="btnConfirmMessage" runat="server" CssClass="btn" 
                    OnClick="btnConfirmMessage_Click" Text="制定完毕"  />
              
            </td>
        </tr>
    </table>
    <asp:GridView runat="server" ID="gvwWarningStart" CssClass="mainlist" AutoGenerateColumns="False"
        EmptyDataText="暂无制定的规则！" OnRowDataBound="gvwWarningStart_RowDataBound" DataKeyNames="MessageDetailId">
        <Columns>
            <asp:TemplateField HeaderText="序号">
                <ItemTemplate>
                    <%# Container.DataItemIndex + 1 + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)%></ItemTemplate>
                <HeaderStyle Width="30px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="预警对象">
                <ItemTemplate>
                    <asp:Label ID="lblHospitalName" ToolTip='<%#Eval("HospitalName") %>' runat="server"
                        Text='<%#Eval("HospitalName") %>' ReadOnly="true"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="地区">
                <ItemTemplate>
                    <asp:Label ID="lblAreaName" ToolTip='<%#Eval("AreaName") %>' runat="server" Text='<%#Eval("AreaName") %>'
                        ReadOnly="true"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TypeName" HeaderText="类型" ReadOnly="true" />
            <asp:TemplateField HeaderText="药品名">
                <ItemTemplate>
                    <asp:Label ID="lblProductName" ToolTip='<%#Eval("ProductName") %>' runat="server"
                        Text='<%#Eval("ProductName") %>' ReadOnly="true"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="类别">
                <ItemTemplate>
                    <asp:Label ID="lblSortName" ToolTip='<%#Eval("SortName") %>' runat="server" Text='<%#Eval("SortName") %>'
                        ReadOnly="true"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="AddTime" HeaderText="添加时间" DataFormatString="{0:d}" ReadOnly="true" />
            <asp:TemplateField HeaderText="触发条件">
                <ItemTemplate>
                    <%#Eval("SqlDescription") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Level" HeaderText="预警级别" ControlStyle-Width="80px" ReadOnly="true" />
            <asp:TemplateField>
                <HeaderTemplate>
                    <input id="addTable_chkAll" name="chkAll" class="chkAll" type="checkbox" onclick="$('input[type=checkbox]').attr('checked', this.checked);" />
                </HeaderTemplate>
                <ItemTemplate>
                    <input type="checkbox" name="chk" class="item" id="chk" value='<%#Eval("MessageDetailId")%>' />
                </ItemTemplate>
                <HeaderStyle Width="25px" />
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <div class="page">
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged">
        </webdiyer:AspNetPager>
    </div>
    <div class="listctrl">
        <asp:Button ID="btnDelte" CssClass="btn" runat="server" Text="删除"  OnClick="btnDelte_Click"
            UseSubmitBehavior="false" 
            onclientclick="if(getcheckcount('请至少选择一个要删除的预警')){ return confirm('确定要删除所选的预警吗？');} return false;" />
        <asp:Button ID="btnStart" CssClass="btn" runat="server" Text="启用"   OnClick="btnStart_Click"
            UseSubmitBehavior="false" />
    </div>

    <script type="text/javascript">
        //验证预警规则的预警范围 预警数量 预警金额
        function ValidateWarning() {
            var flag = true;
            //ddlTime预警范围
            var ddlTime = document.getElementById('ctl00_ContentPlaceHolder1_ddlTime');
            var txtTime = document.getElementById('ctl00_ContentPlaceHolder1_txtTimeOfRange');
            //ddlCountCompare、ddlCountCompare2预警数量范围比较方式
            var ddlCountCompare = document.getElementById('ctl00_ContentPlaceHolder1_ddlCountCompare');
            var ddlCountCompare2 = document.getElementById('ctl00_ContentPlaceHolder1_ddlCountCompare2');
            var txtCount = document.getElementById('ctl00_ContentPlaceHolder1_txtCount');
            var txtCount2 = document.getElementById('ctl00_ContentPlaceHolder1_txtCount2');


            //下拉框ddlAmountCompare、ddlAmountCompare2预警金额范围比较方式（value值： 1大于等于 0小于等于）
            var ddlAmountCompare = document.getElementById('ctl00_ContentPlaceHolder1_ddlAmountCompare');
            var ddlAmountCompare2 = document.getElementById('ctl00_ContentPlaceHolder1_ddlAmountCompare2');
            var txtAmount = document.getElementById('ctl00_ContentPlaceHolder1_txtAmount');
            var txtAmount2 = document.getElementById('ctl00_ContentPlaceHolder1_txtAmount2');
            //下拉框ddlTime的value 1是周 2月  3季度 4年
            if (ddlTime.value == '1') {
                if (txtTime.value > 5) {
                    alert("监控周不可以超过5个自然周");
                    flag = false;
                }
            }
            if (ddlTime.value == '2') {
                if (txtTime.value > 5) {
                    alert("监控周不可以超过5个自然月");
                    flag = false;
                }
            }
            if (ddlTime.value == '3') {
                if (txtTime.value > 5) {
                    alert("监控周不可以超过5个自然季度");
                    flag = false;
                }
            }
            //对预警数量判断
            if (ddlCountCompare.value == "1") {
                //数量大于第一个数字，且大于第二个数字
                if (ddlCountCompare2.value == "1") {
                    alert('预警数量不可以同时大于等于');
                    flag = false;
                }
            }
            else {
                //数量小于第一个数字，且小于第二个数字
                if (ddlCountCompare2.value == "0") {
                    alert('预警数量不可以同时小于等于');
                    flag = false;
                }
            }
            //对预警金额判断
            if (ddlAmountCompare.value == "1") {
                //数量大于第一个数字，且大于第二个数字
                if (ddlAmountCompare2.value == "1") {
                    alert('预警金额不可以同时大于等于');
                    flag = false;
                }
            }
            else {
                //数量小于第一个数字，且小于第二个数字
                if (ddlAmountCompare2.value == "0") {
                    alert('预警数量不可以同时小于等于');
                    flag = false;
                }
            }
            return flag;
        }
    </script>

</asp:Content>


<asp:Content ID="Content3" runat="server" contentplaceholderid="head">

    <style type="text/css">
    .style1
    {
        height: 20px;
    }
</style>

</asp:Content>
